package com.seocoo.worker.order.model;


import com.seocoo.worker.order.req.ReqCancelMeasure;
import com.seocoo.worker.order.req.ReqChangeTakeState;
import com.seocoo.worker.order.req.ReqGoodsMeasureInfo;
import com.seocoo.worker.order.req.ReqMeasureInit;
import com.seocoo.worker.order.req.ReqOrderMeasure;
import com.seocoo.worker.order.req.ReqSetMeasureTime;
import com.seocoo.worker.order.req.ReqTakeOrder;
import com.seocoo.worker.order.req.ReqTaskState;
import com.sfh.lib.mvvm.BaseViewModel;

/**
 * author : Ssp
 * e-mail : 981297079@qq.com
 * date   : 2020/2/2320:32
 * desc   :
 * version: 1.0
 */
public class OrderModel extends BaseViewModel {
    /***
     * 查询接单状态
     */
    public void queryTakeState() {
        this.execute(new ReqTaskState(), baseRsp -> {
            if (baseRsp.success()) {
                setValue("onChangeTakeState", baseRsp.getData());
            } else {
                showDialogToast(baseRsp.getMsg());
            }
        });
    }

    /***
     * 切换接单状态 takeState:1-接单中 2-休息
     */
    public void changeTakeState(String takeState) {
        this.execute(false, new ReqChangeTakeState(takeState), baseRsp -> {
            if (baseRsp.success()) {
                setValue("onChangeTakeState", takeState);
            } else {
                showDialogToast(baseRsp.getMsg());
            }
        });
    }

    /***
     * 录入测量初始化
     */
    public void queryMeasureInit() {
        this.execute(true, new ReqMeasureInit(), eMeasureInitBaseRsp -> {
            if (eMeasureInitBaseRsp.success()) {
                setValue("onMeasureInit", eMeasureInitBaseRsp.getData());
            } else {
                showDialogToast(eMeasureInitBaseRsp.getMsg());
            }
        });
    }

    /***
     * 录入测量信息
     * @param req
     */
    public void addOrderMeasure(ReqOrderMeasure req) {
        this.execute(false, req, eMeasureInitBaseRsp -> {
            hideLoading();
            if (eMeasureInitBaseRsp.success()) {
                setValue("onAddOrderMeasure");
            } else {
                showDialogToast(eMeasureInitBaseRsp.getMsg());
            }
        });
    }

    /**
     * @param req
     */
    public void getOrderMeasureInfo(ReqGoodsMeasureInfo req) {
        this.execute(false, req, eMeasureInitBaseRsp -> {
            if (eMeasureInitBaseRsp.success()) {
                setValue("onGetMeasureInfoSuccess", eMeasureInitBaseRsp.getData());
            } else {
                showDialogToast(eMeasureInitBaseRsp.getMsg());
            }
        });
    }

    /***
     * 设置测量时间
     */
    public void setMeasureTime(String orderId, String measureTime, String measureId) {
        this.execute(false, new ReqSetMeasureTime(orderId, measureTime, measureId), eMeasureInitBaseRsp -> {
            if (eMeasureInitBaseRsp.success()) {
                setValue("onAddOrderMeasure");
            } else {
                showDialogToast(eMeasureInitBaseRsp.getMsg());
            }
        });
    }

    /***
     * 测量接单
     */
    public void takeOrder(String orderId) {
        this.execute(false, new ReqTakeOrder(orderId), eMeasureInitBaseRsp -> {
            if (eMeasureInitBaseRsp.success()) {
                setValue("onTakeOrder", orderId);
            } else {
                showDialogToast(eMeasureInitBaseRsp.getMsg());
            }
        });
    }

    /***
     * 取消测量
     */
    public void cancelMeasure(String measureId) {
        this.execute(false, new ReqCancelMeasure(measureId), eMeasureInitBaseRsp -> {
            if (eMeasureInitBaseRsp.success()) {
                setValue("onCancelMeasure", measureId);
            } else {
                showDialogToast(eMeasureInitBaseRsp.getMsg());
            }
        });
    }

}
